<template>
<div class="distributor-application views-container">
    <el-dialog :visible.sync="dialogVisibleImg" width="30%" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">驳回原因</span>
            </div>
            <p style="padding:20px;min-height:200px">{{openDialogText}}</p>
        </div>
    </el-dialog>
    <el-dialog @close="resetDialogFormData" :visible.sync="dialogTableVisible" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogTableVisible">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">分销商审核</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content">
                    <div class="wlm-dialog-main">
                        <div class="wlm-dialog-content">
                            <el-form ref="userForm" :model="formFormatData.formData" :rules="formFormatData.rules" size="small" label-width="120px" class="retail-form" label-position="right">
                                <el-form-item label="审核状态" prop="name">
                                    <el-radio-group v-model="formFormatData.formData.status">
                                        <!-- <el-radio label="10">待审核</el-radio> -->
                                        <el-radio label="20">审核通过</el-radio>
                                        <el-radio label="30">驳回</el-radio>
                                    </el-radio-group>
                                </el-form-item>
                                <el-form-item label="原因" prop="merchantlog" v-if="formFormatData.formData.status=='30'">
                                    <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" v-model.trim="formFormatData.formData.content">
                                    </el-input>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small" type="primary" @click="formFormatSubmit">确定</el-button>
        </footer>
    </el-dialog>
    <div class="wlm-table">
        <div class="wlm-table-header" style="margin-bottom:20px;">
            <div class="dashboard-header">
                <el-row :gutter="8">
                    <el-col :span="8">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">申请总数</div>
                            <div class="item-num">
                                <span>{{categoryData.total}}</span>
                            </div>
                        </div>
                    </el-col>
                    <!-- <el-col :span="6">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">较上月增长</div>
                            <div class="item-num">
                                <span>{{categoryData.increase}}%</span>
                            </div>
                        </div>
                    </el-col> -->
                    <el-col :span="8">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c">
                            <div class="item-title">通过数量</div>
                            <div class="item-num">
                                <span>{{categoryData.adopt_num}}</span>
                            </div>
                        </div>
                    </el-col>
                    <el-col :span="8">
                        <div class="dashboard-header-item flex-col flex-justify-c flex-align-c ">
                            <div class="item-title">驳回数量</div>
                            <div class="item-num">
                                <span>{{categoryData.not_adopt_num}}</span>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="姓名：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.real_name" placeholder="请输入姓名" style="width:175px;"></el-input>
                    </el-form-item>
                    <el-form-item label="电话：" class="search">
                        <el-input @keyup.enter.native="filesSerch" :minlength="11" v-model="tableFormatData.userTable.files.mobile" placeholder="请输入电话" style="width:175px;"></el-input>
                    </el-form-item>
                    <el-form-item label="用户：" class="search">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.nickName" placeholder="请输入用户昵称" style="width:175px;"></el-input>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column prop="date" label="用户" >
                    <template slot-scope="scope">
                        <div class="wlm-table-logos flex-row">
                            <img class="logo " :src="scope.row.avatarUrl">
                            <div class="inner-text scale-grow">
                                <p class="ellipsis" style="width:150px;">{{scope.row.nickName}}</p>
                                <!-- <div class="flex-row flex-align-c flex-justify-c">ID:{{scope.row.user_id}} -->
                                <el-tooltip class="item" effect="dark" :content="sourceType[`${scope.row.source}`]" placement="top">
                                    <img height="20" width="20" :src="sourceImg[`${scope.row.source || '-'}`]" alt="">
                                </el-tooltip>
                                <!-- </div> -->
                            </div>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="姓名" >
                    <template slot-scope="scope">
                        <span>{{scope.row.real_name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="电话" >
                    <template slot-scope="scope">
                        <span>{{scope.row.mobile||'-'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="推荐人" >
                    <template slot-scope="scope">
                        <span>{{scope.row.refereeName || '平台'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="审核状态" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.apply_status==10">待审核</span>
                        <span v-if="scope.row.apply_status==20">审核通过</span>
                        <span v-if="scope.row.apply_status==30">驳回</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="审核方式" >
                    <template slot-scope="scope">
                        <span v-if="scope.row.apply_type==10">需后台审核</span>
                        <span v-if="scope.row.apply_type==20">无需审核</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="申请时间" width="150px;">
                    <template slot-scope="scope">
                        <span>{{ scope.row.create_time }}</span>
                    </template>
                </el-table-column>
                 <el-table-column prop="name" label="表单信息" width="380px;">
                    <template slot-scope="scope">
                        <div v-for="(item,index) in scope.row.form.pc_value" :key="index">
                       <!-- 单行文本、多行文本、身份证、时间、日期 -->
                        <div style="display:flex;">
                          <div>
                            {{keyValueTitle[item.key] ? keyValueTitle[item.key] :item.name}}:
                          </div>
                            <div v-if="['singletext','manytext','cardnumber','datetext','datatime'].indexOf(item.key) != -1">
                              {{item.default}}
                            </div>
                            <!-- 单选、多选、下拉框 -->
                          <div v-if="['downbox','checkbox','radio'].indexOf(item.key) != -1">
                            <div
                              v-for="(v,i) in item.meal"
                              :key="i"
                            >
                              {{item.default.split(',').indexOf(v.id) !=-1?v.balanceone:''}}
                            </div>
                          </div>
                          <!-- 图片 -->
                          <div v-if="['image'].indexOf(item.key) != -1">
                            <div style="display:flex;">
                              <div
                                v-for="(v,i) in item.default"
                                :key="i"
                              >
                                <img
                                  style="width:50px;height:50px;margin-right:10px;"
                                  :src="v?v:''"
                                >
                              </div>
                            </div>
                            </div>
                            <!-- 日期范围、时间范围 -->
                            <div v-if="['datatextrange','timeframe'].indexOf(item.key) != -1">
                              {{item.name.startname}}:{{item.default.startappointdata}} — {{item.name.endname}}:{{item.default.endappointdata}}

                            </div>
                             <!-- 城市 -->
                              <div v-if="['city'].indexOf(item.key) != -1">
                                {{item.address.province + '-' + item.address.city + '-' + item.address.region}}
                              </div>
                        </div>
                    </div>
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="150px;">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <el-button v-if="scope.row.apply_status==10" class="wlm-text" type="text" @click="newFunction({redirect:'ids',id:scope.row.apply_id,toggle:'dialogTableVisible',noEdit:true}, scope.row.apply_id)">审核</el-button>
                            <p v-if="scope.row.apply_status==20">-</p>
                            <el-button v-if="scope.row.apply_status==30" class="wlm-text" type="text" @click="openDialog(scope.row.reject_reason)">驳回原因</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" type="primary" :disabled="isGroup" size="mini"  @click="auditBatch({redirect:'ids',id:'all',toggle:'dialogTableVisible',noEdit:true})">批量审核</el-button>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  applyList,
  applyCheck,
  applyStatistics,
  applyDelete,
  dealerApplyDelete
} from '@/api/distribution'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table'), mixins.getters('Form')],
  name: 'DistributorApplication',
  components: {
  },
  created() {
    applyStatistics().then((response) => {
      const {
        data: {
          data: msgData = []
        }
      } = response
      this.categoryData = msgData
      console.log(this.categoryData)
    })
  },
  data() {
    return {
        keyValueTitle: {
        datatextrange: '日期范围',
        timeframe: '时间范围',
      },
      categoryData: {},
      dialogVisibleImg: false,
      dialogTableVisible: false,
      openDialogText: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: applyList,
            delList: dealerApplyDelete
          },
          tableData: [],
          files: {
            real_name: '',
            nickName: '',
            mobile: '',
            ids: [],
            checkall: '0',
            Recycle: '1',
            redirect: 'apply_id'
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      },
      formFormatData: {
        key: 'userForm',
        model: {
          noCreateEdit: false,
          bindDialog: 'dialogTableVisible'
        },
        api: {
          editForm: {
            api: applyCheck,
            params: {
              id: ''
            }
          },
          submitForm: applyCheck
        },
        formData: {
          ids: [],
          content: '',
          status: '20'
        },
        rules: {

        }
      }
    }
  },
  methods: {

    newFunction(params, id) {
      this.formFormatDialogEditEvt(params)
      this.formFormatData.formData.ids = [id]
    },
    openDialog(params) {
      this.openDialogText = params
      this.dialogVisibleImg = true
    },
    auditBatch(params) {
      this.formFormatDialogEditEvt(params)
      var array = []
      this.tableFormatData.userTable.files.ids.map((item) => {
        array.push(item.apply_id)
      })
      this.formFormatData.formData.ids = array
    }
  }
}
</script>
